package com.powernobug.service.impl;

import com.powernobug.bean.model.MarketSystem;
import com.powernobug.bean.model.MarketSystemExample;
import com.powernobug.bean.vo.BaseRespVo;
import com.powernobug.bean.vo.data.ConfigExpressData;
import com.powernobug.bean.vo.data.ConfigOrderData;
import com.powernobug.bean.vo.data.ConfigWXData;
import com.powernobug.mapper.MarketSystemMapper;
import com.powernobug.service.AdminConfigService;
import com.powernobug.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @description:
 * @project: project1-no-bug
 * @package: com.powernobug.service.impl
 * @author: HuangWeiLong
 * @date: 2024/8/26 23:29
 */
public class AdminConfigServiceImpl implements AdminConfigService {
    @Override
    public BaseRespVo express() {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        MarketSystemMapper marketSystemMapper = sqlSession.getMapper(MarketSystemMapper.class);

        MarketSystemExample marketSystemExample1 = new MarketSystemExample();
        MarketSystemExample.Criteria market_express_freight_min = marketSystemExample1.createCriteria().andKeyNameEqualTo("market_express_freight_min");
        List<MarketSystem> marketSystems1 = marketSystemMapper.selectByExample(marketSystemExample1);
        Integer keyValue1 = Integer.parseInt(marketSystems1.get(0).getKeyValue());

        MarketSystemExample marketSystemExample2 = new MarketSystemExample();
        MarketSystemExample.Criteria market_express_freight_value = marketSystemExample2.createCriteria().andKeyNameEqualTo("market_express_freight_value");
        List<MarketSystem> marketSystems2 = marketSystemMapper.selectByExample(marketSystemExample2);
        Integer keyValue2 = Integer.parseInt(marketSystems2.get(0).getKeyValue());


        ConfigExpressData configExpressData = ConfigExpressData.builder().marketExpressFreightMin(keyValue1).marketExpressFreightValue(keyValue2).build();
        return BaseRespVo.ok(configExpressData);
    }

    @Override
    public BaseRespVo order() {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        MarketSystemMapper marketSystemMapper = sqlSession.getMapper(MarketSystemMapper.class);

        MarketSystemExample marketSystemExample1 = new MarketSystemExample();
        MarketSystemExample.Criteria marketOrderComment = marketSystemExample1.createCriteria().andKeyNameEqualTo("market_order_comment");
        List<MarketSystem> marketSystems1 = marketSystemMapper.selectByExample(marketSystemExample1);
        Integer keyValue1 = Integer.parseInt(marketSystems1.get(0).getKeyValue());

        MarketSystemExample marketSystemExample2 = new MarketSystemExample();
        MarketSystemExample.Criteria marketOrderUnconfirm = marketSystemExample2.createCriteria().andKeyNameEqualTo("market_order_unconfirm");
        List<MarketSystem> marketSystems2 = marketSystemMapper.selectByExample(marketSystemExample2);
        Integer keyValue2 = Integer.parseInt(marketSystems2.get(0).getKeyValue());

        MarketSystemExample marketSystemExample3 = new MarketSystemExample();
        MarketSystemExample.Criteria marketOrderUnpaid = marketSystemExample3.createCriteria().andKeyNameEqualTo("market_order_unpaid");
        List<MarketSystem> marketSystems3 = marketSystemMapper.selectByExample(marketSystemExample3);
        Integer keyValue3 = Integer.parseInt(marketSystems3.get(0).getKeyValue());


        ConfigOrderData configOrderData = ConfigOrderData.builder().marketOrderComment(keyValue1).marketOrderUnconfirm(keyValue2).marketOrderUnpaid(keyValue3).build();
        return BaseRespVo.ok(configOrderData);
    }

    @Override
    public BaseRespVo wx() {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        MarketSystemMapper marketSystemMapper = sqlSession.getMapper(MarketSystemMapper.class);

        MarketSystemExample marketSystemExample1 = new MarketSystemExample();
        MarketSystemExample.Criteria marketWxCatlogGoods = marketSystemExample1.createCriteria().andKeyNameEqualTo("market_wx_catlog_goods");
        List<MarketSystem> marketSystems1 = marketSystemMapper.selectByExample(marketSystemExample1);
        Integer keyValue1 = Integer.parseInt(marketSystems1.get(0).getKeyValue());

        MarketSystemExample marketSystemExample2 = new MarketSystemExample();
        MarketSystemExample.Criteria marketWxCatlogList = marketSystemExample2.createCriteria().andKeyNameEqualTo("market_wx_catlog_list");
        List<MarketSystem> marketSystems2 = marketSystemMapper.selectByExample(marketSystemExample2);
        Integer keyValue2 = Integer.parseInt(marketSystems2.get(0).getKeyValue());

        MarketSystemExample marketSystemExample3 = new MarketSystemExample();
        MarketSystemExample.Criteria marketWxIndexBrand = marketSystemExample3.createCriteria().andKeyNameEqualTo("market_wx_index_brand");
        List<MarketSystem> marketSystems3 = marketSystemMapper.selectByExample(marketSystemExample3);
        Integer keyValue3 = Integer.parseInt(marketSystems3.get(0).getKeyValue());

        MarketSystemExample marketSystemExample4 = new MarketSystemExample();
        marketSystemExample4.createCriteria().andKeyNameEqualTo("market_wx_index_hot");
        List<MarketSystem> marketSystems4 = marketSystemMapper.selectByExample(marketSystemExample4);
        Integer keyValue4 = Integer.parseInt(marketSystems4.get(0).getKeyValue());

        MarketSystemExample marketSystemExample5 = new MarketSystemExample();
        marketSystemExample5.createCriteria().andKeyNameEqualTo("market_wx_index_new");
        List<MarketSystem> marketSystems5 = marketSystemMapper.selectByExample(marketSystemExample5);
        Integer keyValue5 = Integer.parseInt(marketSystems5.get(0).getKeyValue());

        MarketSystemExample marketSystemExample6 = new MarketSystemExample();
        marketSystemExample6.createCriteria().andKeyNameEqualTo("market_wx_index_topic");
        List<MarketSystem> marketSystems6 = marketSystemMapper.selectByExample(marketSystemExample6);
        Integer keyValue6 = Integer.parseInt(marketSystems6.get(0).getKeyValue());

        MarketSystemExample marketSystemExample7 = new MarketSystemExample();
        marketSystemExample7.createCriteria().andKeyNameEqualTo("market_wx_share");
        List<MarketSystem> marketSystems7 = marketSystemMapper.selectByExample(marketSystemExample7);
        boolean keyValue7 = Boolean.parseBoolean(marketSystems7.get(0).getKeyValue());


        ConfigWXData configWXData = ConfigWXData.builder().marketWxCatlogGoods(keyValue1)
                .marketWxCatlogList(keyValue2).marketWxIndexBrand(keyValue3)
                .marketWxIndexHot(keyValue4).marketWxIndexNew(keyValue5)
                .marketWxIndexTopic(keyValue6).marketWxShare(keyValue7).build();
        return BaseRespVo.ok(configWXData);
    }
}
